﻿using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Nantianmen.Domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Nantianmen.EntityFrameworkCore.ValueConveters
{
    public class QueryParameterMatchModeValueConverter : ValueConverter<QueryParameterMatchMode?, string?>
    {
        public QueryParameterMatchModeValueConverter(Expression<Func<QueryParameterMatchMode?, string?>> convertToProviderExpression, Expression<Func<string?, QueryParameterMatchMode?>> convertFromProviderExpression, ConverterMappingHints? mappingHints = null) : base(convertToProviderExpression, convertFromProviderExpression, mappingHints)
        {
        }

        public QueryParameterMatchModeValueConverter() : this(
            value => value == null ? null : value.ToString(),
            text => string.IsNullOrWhiteSpace(text) ? null : Enum.Parse<QueryParameterMatchMode>(text))
        {

        }
    }
}
